# the minimum version of CMake.
cmake_minimum_required(VERSION 3.5.0)
project(mindspore_lite_llm)

set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})

if(DEFINED PACKAGE_FIND_FILE)
    include(${PACKAGE_FIND_FILE})
endif()

include_directories(${NATIVERENDER_ROOT_PATH}
                    ${NATIVERENDER_ROOT_PATH}/include)

# 编译 mindspore_lite_llm 库
file(GLOB_RECURSE SOURCES
    src/*.cpp)
add_library(mindspore_lite_llm SHARED ${SOURCES})

# 设置输出库名称为 libmindspore_lite_llm.so
set_target_properties(mindspore_lite_llm PROPERTIES OUTPUT_NAME "mindspore_lite_llm")

# 链接必要的库
target_link_libraries(mindspore_lite_llm PUBLIC ${NATIVERENDER_ROOT_PATH}/../../../libs/${OHOS_ARCH}/liblite-turbo.so)
target_link_libraries(mindspore_lite_llm PUBLIC hilog_ndk.z
                                   libace_napi.z.so
                                   mindspore_lite_ndk)

# 如果需要保留原来的entry库（包含napi_init.cpp）
file(GLOB_RECURSE ENTRY_SOURCES napi_init.cpp)
if(ENTRY_SOURCES)
    add_library(entry SHARED ${ENTRY_SOURCES})
    target_link_libraries(entry PUBLIC mindspore_lite_llm)
    target_link_libraries(entry PUBLIC hilog_ndk.z libace_napi.z.so)
endif()

## the minimum version of CMake.
#cmake_minimum_required(VERSION 3.5.0)
#project(mindspore_lite_llm)
#
## 设置构建类型为 Release
#set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Build type" FORCE)
#
## 基本的编译标志设置（移除了 -fvisibility=hidden）
#set(CMAKE_CXX_FLAGS_RELEASE "-O3 -DNDEBUG -fno-builtin -ffunction-sections -fdata-sections")
#set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG -fno-builtin -ffunction-sections -fdata-sections")
#
## 关键：完全禁用调试信息生成
#add_compile_options(
#    "$<$<CONFIG:Release>:-g0>"  # 完全禁用调试信息
#)
#
#set(CMAKE_SHARED_LINKER_FLAGS_RELEASE
#    "-Wl,--gc-sections -Wl,--exclude-libs,ALL -Wl,-z,now -Wl,-z,relro -Wl,--as-needed"
#)
#
#set(NATIVERENDER_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR})
#
#if(DEFINED PACKAGE_FIND_FILE)
#    include(${PACKAGE_FIND_FILE})
#endif()
#
#include_directories(${NATIVERENDER_ROOT_PATH}
#                    ${NATIVERENDER_ROOT_PATH}/include)
#
## 编译 mindspore_lite_llm 库
#file(GLOB_RECURSE SOURCES
#    src/*.cpp)
#add_library(mindspore_lite_llm SHARED ${SOURCES})
#
## 设置目标属性 - 只对 mindspore_lite_llm 应用符号隐藏
#set_target_properties(mindspore_lite_llm PROPERTIES
#    OUTPUT_NAME "mindspore_lite_llm"
#    # 注释掉符号隐藏，或者只在内部符号上使用
#    # CXX_VISIBILITY_PRESET hidden
#    # VISIBILITY_INLINES_HIDDEN ON
#)
#
## 为特定目标设置编译选项
#target_compile_options(mindspore_lite_llm PRIVATE
#    $<$<CONFIG:Release>:-g0>
#    $<$<CONFIG:Release>:-O3>
#    $<$<CONFIG:Release>:-DNDEBUG>
#)
#
## 链接选项 - 移除符号隐藏相关的选项
#target_link_options(mindspore_lite_llm PRIVATE
#    $<$<CONFIG:Release>:-Wl,--gc-sections>
#    $<$<CONFIG:Release>:-Wl,--exclude-libs,ALL>
#)
#
#target_link_libraries(mindspore_lite_llm PUBLIC
#    ${NATIVERENDER_ROOT_PATH}/../../../libs/${OHOS_ARCH}/liblite-turbo.so
#    hilog_ndk.z
#    libace_napi.z.so
#    mindspore_lite_ndk
#)
#
## entry 库 - 不应用符号隐藏
#file(GLOB_RECURSE ENTRY_SOURCES napi_init.cpp)
#if(ENTRY_SOURCES)
#    add_library(entry SHARED ${ENTRY_SOURCES})
#    target_link_libraries(entry PUBLIC mindspore_lite_llm)
#    target_link_libraries(entry PUBLIC hilog_ndk.z libace_napi.z.so)
#
#    # 对entry库应用优化但不隐藏符号
#    target_compile_options(entry PRIVATE
#        $<$<CONFIG:Release>:-g0>
#        $<$<CONFIG:Release>:-O3>
#        $<$<CONFIG:Release>:-DNDEBUG>
#    )
#endif()
#
## 添加strip命令（可选）
#if(CMAKE_BUILD_TYPE STREQUAL "Release")
#    find_program(STRIP_PROGRAM llvm-strip)
#    if(STRIP_PROGRAM)
#        add_custom_command(TARGET mindspore_lite_llm POST_BUILD
#            COMMAND ${STRIP_PROGRAM} --strip-all $<TARGET_FILE:mindspore_lite_llm>
#            COMMENT "Stripping debug symbols from mindspore_lite_llm"
#        )
#        add_custom_command(TARGET entry POST_BUILD
#            COMMAND ${STRIP_PROGRAM} --strip-all $<TARGET_FILE:entry>
#            COMMENT "Stripping debug symbols from entry"
#        )
#    endif()
#endif()